﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using BoardPACUtil.Util;

namespace BoardPACDSWS
{
    public class Global : System.Web.HttpApplication
    {
        protected static string userId = string.Empty;
        protected static string userDisplayName = string.Empty;
        protected static string userName = string.Empty;
        protected static string format = string.Empty;
        protected static string action = string.Empty;
        protected static string controller = string.Empty;

        protected void Application_Start(object sender, EventArgs e)
        {
            log4net.Config.XmlConfigurator.Configure(new System.IO.FileInfo(Server.MapPath(@"log4net.xml")));
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            userId = Request.Headers[ApplicationConstants.USERID];
            userDisplayName = Request.Headers[ApplicationConstants.USERDISPLAYNAME];
            userName = Request.Headers[ApplicationConstants.USERNAME];
            format = Request.Headers[ApplicationConstants.FORMAT];
            action = Request.Headers[ApplicationConstants.ACTION];
            controller = Request.Headers[ApplicationConstants.CONTROLLER];
        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }

        internal static int UserId { get { int defaultId = 0; int.TryParse(userId, out defaultId); return defaultId; } }
        internal static string UserDisplayName { get { return userDisplayName; } }
        internal static string UserName { get { return userName; } }
        internal static string Format { get { return format; } }
        internal static string Action { get { return action; } }
        internal static string Controller { get { return controller; } }
    }
}